package TCPTest06;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.concurrent.*;

public class Server {

    /**
     * 线程池版 TCP 上传
     * @param args
     */
    public static void main(String[] args) throws IOException {
        ServerSocket ss = new ServerSocket(10000);
        ThreadPoolExecutor pool = new ThreadPoolExecutor(
                3,
                16,
                60,
                TimeUnit.SECONDS,
                new ArrayBlockingQueue<>(2),
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.AbortPolicy()
        );

        while (true) {
            //等待客户端端连接
            Socket s =  ss.accept();
            //开启一条线程，
            // 一个用户对应一个线程，
           //  new Thread(new MyRunnable(s)).run();
            pool.submit(new MyRunnable(s));
        }
    }
}
